home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / dte5_1.zip / COMMON.H < prev    next >
C/C++ Source or Header  |  1991-02-06  |  11KB  |  268 lines

  1. /*
  2.  * Written by Douglas Thomson (1989/1990)
  3.  *
  4.  * This source code is released into the public domain.
  5.  */
  6.  
  7. /*
  8.  * This file contains all the includes, defines, types and function
  9.  *  prototypes that are common to all the editor modules.
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <string.h>
  14. #include <ctype.h>
  15. #ifdef __TURBOC__
  16. #include <stdlib.h>
  17. #endif
  18.  
  19. /*
  20.  * The following defines allow the same source code to be compiled under
  21.  *  both K&R C and more modern C compilers that support prototypes.
  22.  */
  23. #ifdef PROTO
  24. #define ARGS(a) a
  25. #else
  26. #define ARGS(a) ()
  27. #endif
  28.  
  29. #define RECOVERY "DTESAVE"      /* recovery file name */
  30. #define HELPFILE "/usr/local/lib/dte.hlp"   /* help file name */
  31.  
  32. #define MAX_COLS 80             /* widest screen ever used */
  33. #define MAX_LINES 25            /* highest screen ever used */
  34. #define BUFF_SIZE 256           /* longest line permitted in file */
  35.  
  36. #define CONTROL(c) ((c) & 0x1F) /* for ASCII control characters */
  37. #ifndef ERROR
  38. #define ERROR (-1)              /* abnormal termination */
  39. #endif
  40. #ifndef OK
  41. #define OK 0                    /* normal termination */
  42. #endif
  43. #ifndef TRUE
  44. #define TRUE 1                  /* logical true */
  45. #endif
  46. #ifndef FALSE
  47. #define FALSE 0                 /* logical false */
  48. #endif
  49.  
  50. /*
  51.  * The following defines are used by the "error" function, to indicate
  52.  *  how serious the error is.
  53.  */
  54. #define WARNING 1               /* user must acknowledge, editor continues */
  55. #define FATAL 2                 /* editor aborts - very rare! */
  56. #define DIAG 3                  /* error but no pause and editor continues */
  57. #define TEMP 4                  /* not an error, just tell the use what is
  58.                                     going on at the moment */
  59.  
  60. /*
  61.  * The following defines are used to identify certain position markers in
  62.  *  addition to the usual 0 to 9.
  63.  */
  64. #define START_BLOCK 10          /* marker used for start of blocks */
  65. #define END_BLOCK 11            /* marker used for end of blocks */
  66. #define PREVIOUS 12             /* previous position in text */
  67. #define NO_MARKS 13             /* no. of position markers */
  68.  
  69. #define GLOB_COUNT 0x7FFF       /* no. of matches for global search */
  70.  
  71. #define SAVE_NORMAL 0           /* save normal editor file */
  72. #define SAVE_RECOVERY 1         /* save recovery backup file */
  73.  
  74. /*
  75.  * each screen location needs both a character and an attribute. Here
  76.  *  I have used the IBM PC system, which allows a more efficient
  77.  *  implementation on the PC.
  78.  * Note that this creates all sorts of problems for terminals that
  79.  *  record attribute start and end locations instead of associating
  80.  *  attributes with individual characters.
  81.  */
  82. typedef struct {
  83.     char c;
  84.     char attr;
  85. } screen_chars;
  86.  
  87. /*
  88.  * each line on the screen is an array of character/attribute pairs
  89.  */
  90. typedef screen_chars screen_lines[MAX_COLS];
  91.  
  92. /*
  93.  * Some systems (like the PC) require a special kind of pointer for
  94.  *  arrays larger than (say) 64K. Such pointers are always defined
  95.  *  as 'text_ptr's. (Note: only Turbo C's large data memory models
  96.  *  will compile correctly with this code.)
  97.  */
  98. #ifdef __TURBOC__
  99. typedef char huge *text_ptr;
  100. #else
  101. typedef char *text_ptr;
  102. #endif
  103.  
  104. /*
  105.  * "displays" contain all the status information about what attributes are
  106.  *  used for what purposes, which attribute is currently set, and so on.
  107.  * The editor only knows about one physical screen.
  108.  */
  109. typedef struct {
  110.     int line;                   /* actual line cursor currently on */
  111.     int col;                    /* actual column cursor currently in */
  112.     int nlines;                 /* lines on display device */
  113.     int ncols;                  /* columns on display device */
  114.     int ca_len;                 /* length of cursor addressing string */
  115.     char attr;                  /* current actual attribute */
  116.     char normal;                /* attribute for normal text */
  117.     char flash;                 /* attribute for highlighted text - in fact
  118.                                    flashing would probably not be a good
  119.                                    choice! */
  120.     char block;                 /* attribute for blocked text */
  121. } displays;
  122.  
  123. /*
  124.  * Since there is only one display, and almost all the functions either
  125.  *  refer to it or need to pass it to lower level functions, it is a
  126.  *  global variable.
  127.  * However, by making it a structure rather than leaving all the fields
  128.  *  as separate global variables, it is much less likely that there will
  129.  *  be any confusion.
  130.  */
  131. extern displays g_display;
  132.  
  133. /*
  134.  * On some systems, the screen memory can be accessed directly, so
  135.  *  the actual screen is made a pointer.
  136.  * On most systems, the hw_initialize routine will simply allocate
  137.  *  the required about of space.
  138.  */
  139. extern screen_lines *g_screen;
  140.  
  141. /*
  142.  * "status_infos" contain all the editor status information that is
  143.  *  global to the entire editor (i.e. not dependent on the file or
  144.  *  window)
  145.  */
  146. typedef struct {
  147.     struct s_windows *current_window; /* current active window */
  148.     struct s_file_infos *file_list; /* all active files */
  149.     struct s_windows *window_list; /* all active windows */
  150.     text_ptr match_start;       /* start of matched text */
  151.     text_ptr match_end;         /* end of matched text+1 */
  152.     text_ptr start_mem;         /* first char in main text buffer */
  153.     text_ptr end_mem;           /* last char in main text buffer used+1 */
  154.     text_ptr temp_end;          /* temporary end_mem marker */
  155.     text_ptr max_mem;           /* last char available for storage (+1) */
  156.     int prompt_col;             /* column for putting answer to prompt */
  157.     int prompt_line;            /* line for putting answer to prompt */
  158.     int insert;                 /* in insert mode? */
  159.     int indent;                 /* in auto-indent mode? */
  160.     int unindent;               /* in unindent mode? */
  161.     int tab_size;               /* characters between tab stops */
  162.     int unsaved;                /* file has been modified since autosave? */
  163.     long save_time;             /* time file was last saved (seconds) */
  164.     long save_interval;         /* time between saves */
  165.     char rw_name[MAX_COLS];     /* name of last file read or written */
  166.     char help_file[MAX_COLS];   /* name of help file */
  167.     char recovery[MAX_COLS];    /* file name of recovery file (with path) */
  168.     int ungotcount;             /* no. of chars ungot */
  169.     char ungotbuff[MAX_COLS];   /* ungot characters */
  170.     char line_buff[BUFF_SIZE];  /* for currently edited line */
  171.     int copied;                 /* is line_buff active? */
  172.     text_ptr buff_marker[NO_MARKS]; /* pos markers in line_buff */
  173.     int replace;                /* last search was replace mode? */
  174.     char pattern[MAX_COLS];     /* last search pattern */
  175.     char subst[MAX_COLS];       /* last substitute text */
  176.     int flags;                  /* last search flags */
  177.     char flag_str[MAX_COLS];    /* last flags as string */
  178.     int search_count;           /* no. of searches to do */
  179.     int overlap;                /* overlap between pages for page up etc */
  180.     char wanted;                /* attribute to be used for next output */
  181. } status_infos;
  182.  
  183. /*
  184.  * Again, the fields here are global to the entire program, so a global
  185.  *  variable is used.
  186.  * Note that some of these fields could be statically initialized,
  187.  *  but I have chosen to initialize them dynamically, since that way I
  188.  *  can refer to each field by name. This also lends itself to eventually
  189.  *  using a configuration file.
  190.  */
  191. extern status_infos g_status;
  192.  
  193. /*
  194.  * "file_infos" contain all the information unique to a given file
  195.  */
  196. typedef struct s_file_infos {
  197.     text_ptr start_text;        /* first char in file */
  198.     text_ptr end_text;          /* last char in file (+1) */
  199.     int modified;               /* file has been modified since save? */
  200.     int new_file;               /* is current file new? */
  201.     char file_name[MAX_COLS];   /* name of current file being edited */
  202.     text_ptr marker[NO_MARKS];  /* pos markers in main text */
  203.     int